//
//  mySelfInfo.swift
//  甜言蜜语
//
//  Created by yingli on 16/7/25.
//  Copyright © 2016年 wl. All rights reserved.
//

import Foundation
import SwiftyJSON
//我的页面
class mySelfInfo: mySelfModelInitProtocol {
    var timg: String
    var transfer: String
    var activitynum: String
    var shoucangnum: String
    var diamond: String
    var name: String
    var huatinum: String
    var job: String
    var recruitment: String
    var guanzhunum: String
    var fensinum: String
    var integral: String
    var id: String
    required init(json: JSON) {
        
        timg = json["timg"].stringValue
        transfer = json["transfer"].stringValue
        activitynum = json["activitynum"].stringValue
        shoucangnum = json["shoucangnum"].stringValue
        diamond = json["diamond"].stringValue
        name = json["name"].stringValue
        huatinum = json["huatinum"].stringValue
        job = json["job"].stringValue
        recruitment = json["recruitment"].stringValue
        guanzhunum = json["guanzhunum"].stringValue
        fensinum = json["fensinum"].stringValue
        integral = json["integral"].stringValue
        id = json["id"].stringValue
    }
}
//我的招聘
class mySelfRecruitmentInfo: NewsModelInitProtocol{
    var id: Int
    var title: String
    var unittag: String
    var lift: String
    var unitarea: String
    var pay: String
    var unitaddress: String
    var type: String
    var imgsrc: String
    var unittype: String
    var name: String
    var sex: String
    var age: String
    var positiontype: String
    required init(json: JSON) {
        
        id = json["id"].intValue
        title = json["title"].stringValue
        unittag = json["unittag"].stringValue
        lift = json["lift"].stringValue
        unitarea = json["unitarea"].stringValue
        pay = json["pay"].stringValue
        unitaddress = json["unitaddress"].stringValue
        type = json["type"].stringValue
        imgsrc = json["imgsrc"].stringValue
        unittype = json["unittype"].stringValue
        name = json["name"].stringValue
        sex = json["sex"].stringValue
        age = json["age"].stringValue
        positiontype = json["positiontype"].stringValue
        
    }

}
//我的转让
class mySelfTransferInfo: mySelfModelInitProtocol{
    var id: String
    var name: String
    var imgsrc: String
    var price: String
    var ptime: String
    var newold: String
    var type: String
    var area: String
    var address: String
    
    required init(json: JSON) {
    
        id = json["id"].stringValue
        name = json["name"].stringValue
        imgsrc = json["imgsrc"].stringValue
        price = json["price"].stringValue
        ptime = json["ptime"].stringValue
        newold = json["newold"].stringValue
        type = json["type"].stringValue
        area = json["area"].stringValue
        address = json["address"].stringValue
   }
}
//我的活动
class mySelfMyActivityInfo: mySelfModelInitProtocol{
    var id: Int
    var title: String
    var publishtime: String
    var imgsrc: String
    var applynum: String
    required init(json: JSON) {
        
        id = json["id"].intValue
        title = json["title"].stringValue
        publishtime = json["publishtime"].stringValue
        imgsrc = json["imgsrc"].stringValue
        applynum = json["applynum"].stringValue
           }
}

//我的关注
class mySelfConcernInfo: mySelfModelInitProtocol{
    var id: Int
    var title: String
    var publishtime: String
    var imgsrc: String
    var applynum: String
    required init(json: JSON) {
        
        id = json["id"].intValue
        title = json["title"].stringValue
        publishtime = json["publishtime"].stringValue
        imgsrc = json["imgsrc"].stringValue
        applynum = json["applynum"].stringValue
    }
}
//我的收藏
class mySelfCollectionInfo: NewsModelInitProtocol{
    
    var wznum: String
    var gsnum: String
    var ppnum: String
    var sc: [mySelfCollectionListInfo]?
    
    required init(json: JSON) {
        
        wznum = json["wznum"].stringValue
        gsnum = json["gsnum"].stringValue
        ppnum = json["ppnum"].stringValue
        sc = ModelArrayProvider.arrayModel(mySelfCollectionListInfo.self, json: json["sc"])
        
    }
}
//我的收藏
class mySelfCollectionNewModelInfo: NewsModelInitProtocol{
    
    var wznum: String
    var gsnum: String
    var ppnum: String
    var sc: [NewsModel]?
    
    required init(json: JSON) {
        
        wznum = json["wznum"].stringValue
        gsnum = json["gsnum"].stringValue
        ppnum = json["ppnum"].stringValue
        sc = ModelArrayProvider.arrayModel(NewsModel.self, json: json["sc"])
        
    }
}
//我的收藏里面的数组
class mySelfCollectionListInfo: NewsModelInitProtocol{
    
    var celltype: CellType!
    var tname: String
    var ptime: String
    var title: String
    var sharenum: String
    var tags: String
    var menuurl: String
    var img: [Img]?
    var imgsrc: String
    var docid: String
    var replyCount: String
    var type: String
    var id: String
    var isshoucang: Bool
    var url3w: String
    var contributor: String
    var browsenum: String
    var price: String
    var digest: String
    var name: String
    var imgType: Int?
    var imgextra: [String]?
    var logo: String
    var timg: String
    var unitname: String
    var unitarea: String
    var unittype: String
    var unitaddress: String
    var introduction: String
    var ads: [Ads]?
    var hasHead: Int?
    var reputation: String
    
    required init(json: JSON) {
        
        tname = json["tname"].stringValue
        ptime = json["ptime"].stringValue
        title = json["title"].stringValue
        sharenum = json["sharenum"].stringValue
        tags = json["tags"].stringValue
        menuurl = json["menuurl"].stringValue
        imgsrc = json["imgsrc"].stringValue
        docid = json["docid"].stringValue
        replyCount = json["replyCount"].stringValue
        type = json["type"].stringValue
        id = json["id"].stringValue
        isshoucang = json["isshoucang"].boolValue
        url3w = json["url3w"].stringValue
        contributor = json["contributor"].stringValue
        browsenum = json["browsenum"].stringValue
        price = json["price"].stringValue
        digest = json["digest"].stringValue
        img = ModelArrayProvider.arrayModel(Img.self, json: json["img"])
        name = json["name"].stringValue
        imgType = json["imgType"].intValue
        imgextra = ModelArrayProvider.arrayWithJson(json["imgextra"])
        logo = json["logo"].stringValue
        timg = json["timg"].stringValue
        unitname = json["unitname"].stringValue
        unitarea = json["unitarea"].stringValue
        unittype = json["unittype"].stringValue
        unitaddress = json["unitaddress"].stringValue
        introduction = json["introduction"].stringValue
        ads = ModelArrayProvider.arrayModel(Ads.self, json: json["ads"])
        hasHead = json["hasHead"].intValue
        reputation = json["reputation"].stringValue
        self.judgeCellType()
    }
}

extension mySelfCollectionListInfo {
    func judgeCellType() {
        if self.ads != nil {
            self.celltype = .ScrollPictureCell
        }else if self.hasHead != nil || Int(self.type)! == 1 || Int(self.type)! == 4 {
            self.celltype = .TopBigPictureCell
        }else if let imgType = self.imgType where imgType > 0 {
            self.celltype = .BigPictureCell
        }else if self.imgextra != nil || Int(self.type)! == 2 {
            self.celltype = .ThreePictureCell
        }else if Int(self.type)! == 7{
            self.celltype = .BigPictureCell
        }else {
            self.celltype = .NormalNewsCell
        }
    }
    
    
}
/**
 每一种类型的新闻对应的应该展示的cell的种类
 
 - ScrollPictureCell: 滚动新闻
 - NormalNewsCell:    一般新闻(普通新闻、专题新闻、直播等等，这种cell主要特征是只有一张图片)
 - ThreePictureCell:  多图新闻(这种新闻cell有三张图片)
 - BigPictureCell:    大图新闻(这种cell主要特征是有一大张图片)//这个目前是无图新闻，名字没有改
 - TopBigPictureCell: 顶部的大图(这种cell主要特征是有一大张图片)
 */
enum Celltype : String{
    
    case ScrollPictureCell, NormalNewsCell, ThreePictureCell, BigPictureCell, TopBigPictureCell, ReadNormalNewsCell, ReadThreePictureCell, ReadBigPictureCell
    
    func cellHeight() -> CGFloat {
        switch self {
        case .ScrollPictureCell, TopBigPictureCell:
            return 236
        case .NormalNewsCell:
            return 90
        case .ThreePictureCell:
            return 108
        case .BigPictureCell:
            return 50
        case .ReadBigPictureCell:
            return 295
        case .ReadNormalNewsCell:
            return 143
        case .ReadThreePictureCell:
            return 281
        }
    }
}
//我的关注
class myConcernInfo: NewsModelInitProtocol{
    
    var users: [myConcernUserInfo]
    var guanzhunum: String
    var fensinum: String
    
    
    required init(json: JSON) {
        
        users = ModelArrayProvider.arrayModel(myConcernUserInfo.self, json: json["users"])!
        guanzhunum = json["guanzhunum"].stringValue
        fensinum = json["fensinum"].stringValue
    }
}
//我的关注里面的数组
class myConcernUserInfo: NewsModelInitProtocol{
    
    var id: String
    var phone: String
    var name: String
    var timg: String
    var isme: Bool
    var isguanzhu: Bool
    var guanzhunum: String
    var fensinum: String
    var backimg: String
    var signature: String
    var membertypecn: String
    var integral: String
    var diamond: String
    
    required init(json: JSON) {
       id = json["id"].stringValue
        phone = json["phone"].stringValue
        name = json["name"].stringValue
        timg = json["timg"].stringValue
        isme = json["isme"].boolValue
        isguanzhu = json["isguanzhu"].boolValue
        guanzhunum = json["guanzhunum"].stringValue
        fensinum = json["fensinum"].stringValue
        backimg = json["backimg"].stringValue
        signature = json["signature"].stringValue
        membertypecn = json["membertypecn"].stringValue
        integral = json["integral"].stringValue
        diamond = json["diamond"].stringValue
    }
    
}
//我的话题
class myTopicInfo: NewsModelInitProtocol{

    var id: String
    var message: String
    var timg: String
    var infomationimage: String?
    var infomationtitle: String
    var name: String
    var commenttime: String
    var user: String
    
    required init(json: JSON) {
        
    id = json["id"].stringValue
    message = json["message"].stringValue
    timg = json["timg"].stringValue
    infomationimage = json["infomationimage"].stringValue
    infomationtitle = json["infomationtitle"].stringValue
    name = json["name"].stringValue
    commenttime = json["commenttime"].stringValue
    user = json["user"].stringValue
    
 }
    
}
//我的积分
class myIntegraInfo: NewsModelInitProtocol{
    
    var obj: [myIntegra_OBJInfo]

    required init(json: JSON) {
        
    obj = ModelArrayProvider.arrayModel(myIntegra_OBJInfo.self, json: json["obj"])!
    }
    
}
//我的积分里面的obj数组
class myIntegra_OBJInfo: NewsModelInitProtocol{
    
    var nowdate: String
    var onemonthList: [myIntegra_ONEMONInfo]
    
        required init(json: JSON) {
            
        nowdate = json["nowdate"].stringValue
            
        onemonthList = ModelArrayProvider.arrayModel(myIntegra_ONEMONInfo.self, json: json["onemonthList"])!
        
    }
    
}
//我的积分数组里面的onemonthList数组
class myIntegra_ONEMONInfo: NewsModelInitProtocol{

    var id: String
    var noyear: String
    var nomonth: String
    var noday: String
    var noweek: String
    var message: String
    var balance: String
    var changgetype: String
    var changenum: String
    var type: String
    
    required init(json: JSON) {
        id = json["id"].stringValue
        noyear = json["noyear"].stringValue
        nomonth = json["nomonth"].stringValue
        noday = json["noday"].stringValue
        noweek = json["noweek"].stringValue
        message = json["message"].stringValue
        balance = json["balance"].stringValue
        changgetype = json["changgetype"].stringValue
        changenum = json["changenum"].stringValue
        type = json["type"].stringValue
        
    }
    
}
//我的个人信息——个人用户
class userPersonInfo: NewsModelInitProtocol{
    
    var timg: String
    var id: String
    var birthday: String
    var sex: String
    var unitname: String
    var name: String
    var unitarea: String
    var unitaddress: String
    var membertypecn: String
    var signature: String
    var phone: String
    var weixinname: String
    var qqname: String
    var sinaname: String
        required init(json: JSON) {
            timg = json["timg"].stringValue
            id = json["id"].stringValue
            birthday = json["birthday"].stringValue
            sex = json["sex"].stringValue
            unitname = json["unitname"].stringValue
            name = json["name"].stringValue
            unitarea = json["unitarea"].stringValue
            unitaddress = json["unitaddress"].stringValue
            membertypecn = json["membertypecn"].stringValue
            signature = json["signature"].stringValue
            phone = json["phone"].stringValue
            weixinname = json["weixinname"].stringValue
            qqname = json["qqname"].stringValue
            sinaname = json["sinaname"].stringValue
    }
    
}
class userPersonPhoto: NewsModelInitProtocol{
  
    var id: String
    var imgsrc: String
    
    required init(json: JSON) {
        id = json["id"].stringValue
        imgsrc = json["imgsrc"].stringValue
    }
}
//我的个人信息——企业
class userPersonCompany: NewsModelInitProtocol{
    
    var timg: String
    var id: String
    var unitsize: String
    var unitmain: String
    var unitname: String
    var unitarea: String
    var unitstyle: [userPersonPhoto]?
    var unitlicense: [userPersonPhoto]?
    var unitaddress: String
    var unittype: String
    var unitscale: String
    var signature: String
    var introduction: String
    var phone: String
    var weixinname: String
    var qqname: String
    var sinaname: String
    
    required init(json: JSON) {
        timg = json["timg"].stringValue
        id = json["id"].stringValue
        unitsize = json["unitsize"].stringValue
        unitname = json["unitname"].stringValue
        unitmain = json["unitmain"].stringValue
        unitarea = json["unitarea"].stringValue
        unitaddress = json["unitaddress"].stringValue
        unitscale = json["unitscale"].stringValue
        signature = json["signature"].stringValue
        unittype = json["unittype"].stringValue
        unitstyle = ModelArrayProvider.arrayModel(userPersonPhoto.self, json: json["unitstyle"])
        unitlicense = ModelArrayProvider.arrayModel(userPersonPhoto.self, json: json["unitlicense"])
        introduction = json["introduction"].stringValue
        phone = json["phone"].stringValue
        weixinname = json["weixinname"].stringValue
        qqname = json["qqname"].stringValue
        sinaname = json["sinaname"].stringValue

    }
    
}

